package me.keiwu.user.controller.rpc;

import me.keiwu.pub.data.enums.NoticeType;
import me.keiwu.user.domain.Notice;
import me.keiwu.user.service.NoticeService;
import org.aspectj.weaver.ast.Not;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by kei on 24/02/2018.
 */
@RestController
@RequestMapping("/rpc/notice")
public class NoticeRpcController {

    private static final Logger logger = LoggerFactory.getLogger(NoticeRpcController.class);


    @Autowired
    private NoticeService noticeService;

    @RequestMapping("")
    public Notice notice(Integer noticeType,
                         Long fromUser,
                         Long toUser,
                         @RequestParam(required = false) String addition,
                         boolean redPoint) {
        NoticeType type = NoticeType.parse(noticeType);
        return noticeService.notice(type, fromUser, toUser, addition, redPoint);
    }

    @RequestMapping("/checkNotRead")
    public boolean checkNotRead(Integer noticeType, Long userId) {
        return noticeService.checkNotRead(noticeType,userId);
    }


    @RequestMapping("unique")
    public Notice uniquenNotice(Integer noticeType,
                                String uniqueKey,
                                Long fromUser,
                                Long toUser,
                                @RequestParam(required = false) String addition,
                                Boolean redPoint) {
        logger.info("uniquenNotice noticeType={}, uniqueKey={}, fromUser={} toUser={}, redPoint={}",
                noticeType, uniqueKey, fromUser, toUser, redPoint);
        NoticeType type = NoticeType.parse(noticeType);
        return noticeService.uniqueNotice(type, uniqueKey, fromUser, toUser, addition, redPoint);
    }

    @RequestMapping("/unreadChallengeNotice")
    public Page<Notice> unreadChallengeNotice(int page, int size, int startTime, int endTime) {
        return noticeService.unreadChallengeNoticeList(page, size, startTime, endTime);
    }

}
